home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / modal.exe / TEST.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1993-05-23  |  5.3 KB  |  221 lines

  1. program test;
  2.  
  3. (*
  4.    Test program for MODAL.PAS
  5.  
  6.    Implements a MsgBox procedure to demonstrate the modal window object.
  7.    MsgBox procedure only partially supports the API MessageBox.
  8.  
  9.    Copyright (c) 1993 by Yasser Asmi  (CIS 71543,2252)
  10. *)
  11.  
  12. {$A+,I-,R-,S-,V-,B-,G+,X+,W-}
  13.  
  14. uses
  15.    wintypes, winprocs, win31, strings, objects, owindows, odialogs, bwcc,
  16.    modal;
  17.  
  18. const
  19.    id_test = 201;
  20.    id_exit = 202;
  21.  
  22. type
  23.    t_app = object (tapplication)
  24.       procedure initmainwindow; virtual;
  25.    end;
  26.  
  27.    p_main = ^t_main;
  28.    t_main = object (t_cwindow)
  29.       constructor init (aparent : pwindowsobject;
  30.                         atitle, aid : pchar);
  31.       procedure b_test (var msg : tmessage); virtual id_first + id_test;
  32.       procedure b_exit (var msg : tmessage); virtual id_first + id_exit;
  33.    end;
  34.  
  35.  
  36.    p_msgbox  = ^t_msgbox;
  37.    t_msgbox = object (t_modalwindow)
  38.       constructor init (aparent : pwindowsobject;
  39.                         atxt, acaption : pchar;
  40.                         atexttype : word);
  41.  
  42.       procedure b_yes (var msg : tmessage); virtual id_first + id_yes;
  43.       procedure b_no (var msg : tmessage); virtual id_first + id_no;
  44.  
  45.    end;
  46.  
  47.  
  48. (*-- T_MSGBOX --*)
  49.  
  50. constructor t_msgbox.init;
  51.  
  52. (*
  53.    calls t_modalwindow init
  54.    centers the window
  55.    assigns bwcc background
  56.    creates a divider
  57.    creates a groupbox
  58.    creates a static control
  59.    creates buttons using atexttype (partially supported)
  60. *)
  61.  
  62. var
  63.    p : pwindowsobject;
  64.  
  65.  
  66.  procedure button (anid, xloc : integer;
  67.                    default : boolean);
  68.  
  69.  begin
  70.     p := new (pbutton, init (@self, anid, '',
  71.               dux (xloc), duy (74), 64, 39, default));
  72.  end;
  73.  
  74.  
  75. begin
  76.    inherited init (aparent, acaption, 'MSGBOX');
  77.  
  78.    center_wa (attr, dux (170), duy (116));
  79.    cwndclass.hbrbackground := bwccgetpattern;
  80.  
  81.    p := new (pbdivider, init (@self, -1, '',
  82.              dux (0), duy (66), dux (166), duy (2), false, false));
  83.  
  84.    p := new (pbgroupbox, init (@self, 100, '',
  85.              dux (8), duy (8), dux (150), duy (50)));
  86.  
  87.    p := new (pbstatic, init (@self, 101, atxt,
  88.              dux (13), duy (13), dux (140), duy (40), strlen (atxt)));
  89.  
  90.     case atexttype of
  91.       mb_ok : button (id_ok, 65, true);
  92.       mb_okcancel : begin
  93.                        button (id_ok, 31, true);
  94.                        button (id_cancel, 99, false);
  95.                     end;
  96.       mb_yesno : begin
  97.                     button (id_yes, 31, true);
  98.                     button (id_no, 99, false);
  99.                  end;
  100.    end;
  101. end;
  102.  
  103.  
  104. procedure t_msgbox.b_yes;
  105.  
  106. begin
  107.    endwin (id_yes);
  108. end;
  109.  
  110.  
  111. procedure t_msgbox.b_no;
  112.  
  113. begin
  114.    endwin (id_no);
  115. end;
  116.  
  117.  
  118.  
  119. function msgbox (parent : pwindowsobject;
  120.                  txt, caption : pchar;
  121.                  texttype : word) : integer;
  122.  
  123. (*
  124.    There are two ways of calling run_modal function.  The first one, which
  125.    is commented out in this procedure, allowes you to access variables in
  126.    your objects before destroying the object.  The second one is a
  127.    one-liner.  This is useful when only retval is important.
  128.  
  129.    first method:
  130.       p := new (p_modalwindow, init (...));
  131.                                       -- set attributes here
  132.       ret := run_modal (p, false);    -- call with false
  133.                                       -- access variables here
  134.       p^.done;                        -- must call done
  135.  
  136.     second method:
  137.       ret := run_modal (p_modalwindow, init (...), true);
  138. *)
  139.  
  140. var
  141.    p : p_msgbox;
  142.  
  143. begin
  144. {
  145.    p := new (p_msgbox, init (parent, txt, caption, texttype));
  146.    run_modal (p, false);
  147.    msgbox := p^.retval;
  148.    p^.done;
  149. }
  150.  
  151.    msgbox := run_modal (new (p_msgbox, init (parent, txt, caption, texttype)), true);
  152. end;
  153.  
  154.  
  155. (*-- T_APP --*)
  156.  
  157. procedure t_app.initmainwindow;
  158.  
  159. begin
  160.    mainwindow := new (p_main, init (nil, 'Modal Window Test', 'TEST'));
  161. end;
  162.  
  163.  
  164. (*-- T_MAIN --*)
  165.  
  166. constructor t_main.init;
  167.  
  168. var
  169.    p : pobject;
  170.  
  171. begin
  172.    inherited init (aparent, atitle, aid);
  173.    enablekbhandler;
  174.    attr.x := 0;
  175.    attr.y := 0;
  176.    cwndclass.hbrbackground := getstockobject (ltgray_brush);
  177.  
  178.    p := new (pbutton, init (@self, id_test, '&Test', 10, 10, 50, 26, true));
  179.    p := new (pbutton, init (@self, id_exit, 'E&xit', 80, 10, 50, 26, false));
  180. end;
  181.  
  182.  
  183. procedure t_main.b_exit;
  184.  
  185. begin
  186.    done;
  187. end;
  188.  
  189.  
  190. procedure t_main.b_test;
  191.  
  192. begin
  193.    msgbox (@self, 'This message box is created using a ' +
  194.                   'modal window without any dialog resources.  ' +
  195.                   'Try clicking on the main ' +
  196.                   'window of this application.',
  197.                   'Modal Window', mb_ok);
  198.  
  199.    msgbox (@self, 'Similary, any other dialog can be written ' +
  200.                   'using the modal window object and may contain ' +
  201.                   'any of the OWL controls.',
  202.                   'Modal Window', mb_ok);
  203.    msgbox (@self, 'This allows you to create dialogs dynamically and ' +
  204.                   'control the flow of the application.',
  205.                   'Modal Window', mb_okcancel);
  206.    msgbox (@self, 'Please see the T_MSGBOX.INIT in TEST.PAS and then ' +
  207.                   'look at MODAL.PAS',
  208.                   'Modal Window', mb_yesno);
  209. end;
  210.  
  211.  
  212. var
  213.    app : t_app;
  214.  
  215. begin
  216.    app.init ('TEST');
  217.    app.run;
  218.    app.done;
  219. end.
  220.  
  221.